package Practice1_Collection.P4_EqualsAndHashCode;

import java.util.Objects;

public class Person {
    String firstName;
    String lastName;
    int age;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && Objects.equals(firstName, person.firstName) && Objects.equals(lastName, person.lastName);
    }

    /**
     * 示例代码，实际不这么用
     * @return
     */
    public int hashCode1() {
        int h = 0;
        h = 31 * h + firstName.hashCode();
        h = 31 * h + lastName.hashCode();
        h = 31 * h + age;
        return h;
    }

    @Override
    public int hashCode() {
        return Objects.hash(firstName, lastName, age);
    }
}
